<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <!-- 参数：审计时间 startTime endTime
          审计项目 pro
          问题描述 content -->
          <a-col :md="6" :sm="8">
            <a-form-item label="审计项目">
              <a-input v-model="queryParam.name" @click.native="openSearchModel"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="审计年份">
              <a-date-picker
                mode="year"
                format='YYYY'
                value-format="YYYY"
                placeholder="请选择年份"
                :allowClear="false"
                v-model="queryParam.year"
                :open='yearPickShow'
                @panelChange="handlePanelChange"
                @openChange="handleOpenChange"/>
            </a-form-item>
          </a-col>
          <!-- <a-col :md="6" :sm="8">
            <a-form-item label="审计项目">
              <a-input placeholder="请输入" v-model="queryParam.proId"></a-input>
            </a-form-item>
          </a-col> -->
          <a-col :md="6" :sm="8">
            <a-form-item label="问题描述">
              <a-input placeholder="请输入" v-model="queryParam.content"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="数据范围">
              <a-select v-model="queryParam.type" placeholder="请选择数据范围">
                <a-select-option value="user">创建问题清单</a-select-option>
                <a-select-option value="pro">项目下问题清单</a-select-option>
              </a-select>
              <!-- <a-input v-model="queryParam.name" @click.native="openSearchModel"></a-input> -->
            </a-form-item>
          </a-col>
          <a-col :md="24" :sm="16">
            <span style="float: right; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" style="margin-left: 8px" icon="download" @click="handleExportXls('审计问题列表')">导出</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">清除条件</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <template slot="hiddenText" slot-scope="text">
          <div class="hiddenText" :title="text">
            <div>{{ text.length > 50 ? text.substr(0, 50) + '...' : text }}</div>
          </div>
        </template>
      </a-table>
    </div>

    <ProjectModel ref="projectModal" @getSelect="getProId" />
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { httpAction, getAction, postAction, downFile } from '@/api/manage'
import ProjectModel from './ProjectModel.vue'
import moment from 'moment'
export default {
  name: 'sjxmzb',
  mixins: [JeecgListMixin],
  components: {
    ProjectModel
  },
  data() {
    return {
      disableMixinCreated: true,
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'rowIndex',
          width: 65,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        { title: '索引号', dataIndex: 'syh', width: 80 },
        { title: '责任单位', dataIndex: 'bsjdwName', width: 80 },
        { title: '审计日期', dataIndex: 'sjsj' },
        { title: '审计人员', dataIndex: 'zxrText', width: 100 },
        { title: '定性', dataIndex: 'dingxing', scopedSlots: { customRender: 'hiddenText' }, },
        { title: '定性法规依据', dataIndex: 'dxyj', scopedSlots: { customRender: 'hiddenText' }, },
        { title: '问题描述', dataIndex: 'wtms', scopedSlots: { customRender: 'hiddenText' }, },
        { title: '问题涉及金额', dataIndex: 'tjsjje' },
        { title: '审计过程', dataIndex: 'sjgc', width: 80, },
        { title: '责任界定', dataIndex: 'zrjd', width: 80, },
        { title: '是否整改', dataIndex: 'status_dictText', width: 80, },
        { title: '整改信息', dataIndex: 'zgcmit', width: 80, },
        { title: '整改日期', dataIndex: 'zgdate', width: 80, },
        { title: '整改建议', dataIndex: 'zgjy', width: 80, scopedSlots: { customRender: 'hiddenText' }, },
        { title: '是否境内/外', dataIndex: 'jnw', width: 60, },
        { title: '是否非金额类问题', dataIndex: 'sffjewt', width: 60, },
        { title: '备注', dataIndex: 'remarks', width: 60, },
      ],
      url: {
        list: '/sjxmzygl/sjWorkZtfaProblem/queryProblemList',
        exportXlsUrl: '/sjxmzygl/sjWorkZtfaProblem/exportProblemList',
      },
      yearPickShow: false,
      currentYear:null
    }
  },
  created() {
  },
  methods: {
    getProId(project) {
      this.queryParam.proId = project.id
      this.queryParam.name = project.name
    },
    openSearchModel() {
      this.$refs.projectModal.show()
    },
    handleExportXls(fileName) {
      getAction(this.url.exportXlsUrl).then((res)=>{
        let url = window._CONFIG['domianURL'] + '/sys/common/static/' + res.result;
        const link = document.createElement('a')
        link.style.display = 'none'
        link.href = url;
        link.target = '_blank';
        link.setAttribute('download', fileName + '.xls')
        document.body.appendChild(link)
        link.click()
        document.body.removeChild(link) // 下载完成移除元素
        window.URL.revokeObjectURL(url) // 释放掉blob对象
      })
    },

    timeChange(e) {
      if(e.length) {
        this.$set(this.queryParam, 'startTime', e[0]);
        this.$set(this.queryParam, 'endTime', e[1]);
      }else {
        this.$set(this.queryParam, 'startTime', '');
        this.$set(this.queryParam, 'endTime', '');
      }
    },

    moment,

    handlePanelChange(value) {
      this.queryParam.year = moment(value).format('YYYY')
      this.yearPickShow = false
    },

    handleOpenChange(status) {
      this.yearPickShow = status
    },
  },
}
</script>
<style lang="less" scoped>
.hiddenText {
}
</style>